package com.code.petapp.util;

import android.util.Log;

import com.code.petapp.bean.ClaimsBean;
import com.code.petapp.bean.LostBean;
import com.code.petapp.http.HttpApiService;
import com.code.petapp.http.HttpListener;
import com.code.petapp.http.RetrofitHelper;
import com.code.petapp.http.RxObserver;

import java.util.ArrayList;

public class ClaimsUtils {
    public static void selectAll(String token, HttpListener<ArrayList<ClaimsBean>> httpListener){
        Log.d("Tag","claims start");
        new RetrofitHelper().createApi(HttpApiService.class)
                .selectAllClaims(token)
                .compose(RetrofitHelper.schedulersTransformer())
                .subscribe(new RxObserver<>() {
                    @Override
                    public void success(ArrayList<ClaimsBean> baseBean) {
                        httpListener.success(baseBean);
                    }

                    @Override
                    public void error(int code, String error) {
                        httpListener.error(code,error);
                    }
                });
    }
    public static void selectMy(String token, HttpListener<ArrayList<ClaimsBean>> httpListener){
        Log.d("Tag","claims start");
        new RetrofitHelper().createApi(HttpApiService.class)
                .selectMyClaims(token)
                .compose(RetrofitHelper.schedulersTransformer())
                .subscribe(new RxObserver<>() {
                    @Override
                    public void success(ArrayList<ClaimsBean> baseBean) {
                        httpListener.success(baseBean);
                    }

                    @Override
                    public void error(int code, String error) {
                        httpListener.error(code,error);
                    }
                });
    }
    public static void selectMyDescr(String token,String descr, HttpListener<ArrayList<ClaimsBean>> httpListener){
        Log.d("Tag","claims start");
        new RetrofitHelper().createApi(HttpApiService.class)
                .selectDescrClaims(token,descr)
                .compose(RetrofitHelper.schedulersTransformer())
                .subscribe(new RxObserver<>() {
                    @Override
                    public void success(ArrayList<ClaimsBean> baseBean) {
                        httpListener.success(baseBean);
                    }

                    @Override
                    public void error(int code, String error) {
                        httpListener.error(code,error);
                    }
                });
    }
    public static void update(String token,ClaimsBean claimsBean, HttpListener<String> httpListener){
        Log.d("Tag","lost start");
        new RetrofitHelper().createApi(HttpApiService.class)
                .updateClaims(token,claimsBean)
                .compose(RetrofitHelper.schedulersTransformer())
                .subscribe(new RxObserver<>() {
                    @Override
                    public void success(String data) {
                        httpListener.success(data);
                    }

                    @Override
                    public void error(int code, String error) {
                        httpListener.error(code,error);
                    }
                });
    }
    public static void add(String token,ClaimsBean claimsBean, HttpListener<String> httpListener){
        Log.d("Tag","lost start");
        new RetrofitHelper().createApi(HttpApiService.class)
                .claimsAdd(token,claimsBean)
                .compose(RetrofitHelper.schedulersTransformer())
                .subscribe(new RxObserver<>() {
                    @Override
                    public void success(String data) {
                        httpListener.success(data);
                    }

                    @Override
                    public void error(int code, String error) {
                        httpListener.error(code,error);
                    }
                });
    }
}
